package cn.tedu;

import java.util.Arrays;

//冒泡排序
public class BubbleSort {
    public static void main(String[] args) {
        //数组
        int[] a = {27, 96, 73, 25, 21};
        //嵌套for循环
        //外层循环轮数(a.length-1轮)
        int b = a.length - 1;
        //执行次数取决于i可以取到几个值
        for (int i = 1; i <= a.length - 1; i++) {
            for (int j = 0; j < b; j++) {
                if (a[j] > a[j + 1]) {//相邻比较
                    int t;
                    t = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = t;
                }
            }
            b--;
        }
        System.out.print(Arrays.toString(a));
    }

}
